import Vue from 'vue'
import * as Util from '../components/Util'

let PrintService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.PrintService = Vue.prototype.$PrintService = PrintService
  },

  // 打印发票
  modifyBillNumber (model, row) {
    let data = {
      billcoll: {
        id: model.f_billcoll_id,
        f_bill_id: model.f_bill_id + 1
      },
      detail: {
        f_bill_id: model.f_bill_id,
        f_userinfo_id: row.f_userinfo_id,
        f_user_id: row.f_user_id,
        f_user_name: row.f_user_name,
        f_billdetail_id: row.id,
        f_card_id: row.f_card_id,
        f_bill_type: row.f_bill_type,
        f_bill_state: '已用',
        f_total_money: row.logicmodel.f_preamount,
        f_paid_money: row.logicmodel.f_collection - 0,
        f_operator: Util.f.name,
        f_filiale: Util.f.f_fengongsi,
        f_outlets: Util.f.f_parentname
      },
      type: '打印发票'
    }
    return Vue.resetpost('rs/logic/printBill', {data: data}, {resolveMsg: '打印发票成功', rejectMsg: '打印发票失败'})
  },
  ReissueBill (model, row) {
    let data = {
      billcoll: {
        id: model.f_billcoll_id,
        f_bill_id: model.f_bill_id + 1
      },
      detail: {
        f_bill_id: model.f_bill_id,
        f_billdetail_id: row.id,
        f_bill_state: '已用',
        f_bill_type: `${row.type}(补打)`,
        f_operator: Util.f.name,
        f_filiale: Util.f.f_fengongsi,
        f_outlets: Util.f.f_parentname,
        f_cause: model.f_cause
      },
      type: '票据补打'
    }
    return Vue.resetpost('rs/logic/printBill', {data: data}, {resolveMsg: '补打票据成功', rejectMsg: '补打票据失败'})
  }
}

export default PrintService
